package com.lwm.stream;

import com.lwm.entity.Employee;
import org.junit.Test;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author liweimin
 * @version 1.0
 * @date 2020/9/7 10:20
 */
public class MapTest {
    static List<Employee> employeeList = Arrays.asList(
            new Employee("张三", 23, 6433),
            new Employee("张三1", 33, 4433),
            new Employee("张三2", 63, 65333),
            new Employee("张三3", 43, 5333),
            new Employee("张三4", 36, 4233)
    );
    @Test
    public void test01(){
        List<String> list = Arrays.asList("aaa", "ddd", "dasd", "ddds");
        list.stream().map(String::toUpperCase).forEach(System.out::println);
        employeeList.stream().map(Employee::getName).forEach(System.out::println);
        Stream<Stream<Character>> streamStream = list.stream().map(MapTest::filterCharacter);

        streamStream.forEach((s)->s.forEach(System.out::println));
        //类似于set中的add（Object obj）和addAll(Collection co)
        Stream<Character> characterStream = list.stream().flatMap(MapTest::filterCharacter);
        characterStream.forEach(System.out::println);

    }
    public static Stream<Character> filterCharacter(String string){
        List<Character> list = new ArrayList<>();
        for(Character character:string.toCharArray()){
            list.add(character);
        }
        return list.stream();
    }
    @Test
    public void test02(){
        List<Integer> list = Arrays.asList(1, 1, 4, 4, 56, 6, 87, 88, 9);
        List<Object> list1 = new ArrayList<>();
        list1.addAll(list);
        list1.add(list);
        System.out.println(list1.toString());
    }
}
